package com.github.pig.admin.controller;
import java.util.Map;
import java.util.Date;

import com.github.pig.admin.service.ITbzVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pig.common.constant.CommonConstant;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.pig.common.util.Query;
import com.github.pig.admin.entity.TbzVideo;
import com.github.pig.common.web.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hj
 * @since 2018-03-06
 */
@RestController
@RequestMapping("/video")
public class TbzVideoController extends BaseController {
    @Autowired private ITbzVideoService tbzVideoService;

    /**
    * 通过ID查询
    *
    * @param id ID
    * @return TbzVideo
    */
    @GetMapping("/{id}")
    public TbzVideo get(@PathVariable Integer id) {
        return tbzVideoService.selectById(id);
    }


    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @RequestMapping("/page")
    public Page page(@RequestParam Map<String, Object> params) {
        params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
        return tbzVideoService.selectPage(new Query<>(params), new EntityWrapper<>());
    }

    /**
     * 添加
     * @param  tbzVideo  实体
     * @return success/false
     */
    @PostMapping
    public Boolean add(@RequestBody TbzVideo tbzVideo) {
        return tbzVideoService.insert(tbzVideo);
    }

    /**
     * 删除
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable String id) {
        TbzVideo tbzVideo = new TbzVideo();
        tbzVideo.setId(id);
     //   tbzVideo.setUpdateTime(new Date());
     //  tbzVideo.setDelFlag(CommonConstant.STATUS_DEL);
        return tbzVideoService.updateById(tbzVideo);
    }

    /**
     * 编辑
     * @param  tbzVideo  实体
     * @return success/false
     */
    @PutMapping
    public Boolean edit(@RequestBody TbzVideo tbzVideo) {
    //    tbzVideo.setUpdateTime(new Date());
        return tbzVideoService.updateById(tbzVideo);
    }
}
